import roleConfig from '../../../api/config/roleConfig'
import * as globalTypes from '../../../mutation-types'

/**
 * 查询角色列表
 * @param data
 */
export const queryRole = ({commit, state, rootState, dispatch}, data) => {
  return roleConfig.queryRole(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 新增时获取权限列表
 * @param data
 */
export const showRoleAdd = ({commit, state, rootState, dispatch}, data) => {
  return roleConfig.showRoleAdd(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 新增角色
 * @param data
 */
export const addRole = ({commit, state, rootState, dispatch}, data) => {
  return roleConfig.addRole(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 删除角色
 * @param data
 */
export const delRole = ({commit, state, rootState, dispatch}, data) => {
  return roleConfig.delRole(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询角色详情
 * @param data
 */
export const showRoleEdit = ({commit, state, rootState, dispatch}, data) => {
  return roleConfig.showRoleEdit(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 更新角色详情
 * @param data
 */
export const updateRole = ({commit, state, rootState, dispatch}, data) => {
  return roleConfig.updateRole(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
